package brac;

import java.util.ArrayList;
import fn.*;

public class FixedPoint extends Bracketing {

	@SuppressWarnings("unchecked")
	public void set() {
		String[] s = { "x", "f(x)", "Error" };
		header = s;
		values = new ArrayList[3];
	}

	public int[] fromTo() {

		return new int[] { 0, 0 };
	}

	public FixedPoint() {
		set();
	}

	public void solve(Function fn, double presition, int numOfIteration, double po, double b) {
		ArrayList<Double> pl = new ArrayList<Double>();
		ArrayList<Double> pkl = new ArrayList<Double>();
		ArrayList<Double> errl = new ArrayList<Double>();
		double p = po;

		for (int k = 0; k < numOfIteration; k++) {
			pl.add(po);
			p = feval(fn, po);
			pkl.add(p);
			double err = Math.abs(p - po);
			errl.add(err);

			@SuppressWarnings("unused")
			double relerr = err / (Math.abs(p));
			po = p;
			if (err <= presition)
				break;

		}
		values[0] = pl;
		values[1] = pkl;
		values[2] = errl;
	}

	public String[] header() {
		return header;
	}

	public ArrayList<Double>[] getValues() {
		return values;
	}

	@Override
	public String toString() {
		return "Fixed Point";
	}

}
